package com.trytry.service;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trytry.dao.UserDao;
import com.trytry.entity.Article;
import com.trytry.entity.Page;
import com.trytry.entity.User;
@Service
@Transactional
public class UserServiceImpl implements UserService {
	@Autowired 
	private UserDao userdao;
	

	public UserDao getUserdao() {
		return userdao;
	}


	public void setUserdao(UserDao userdao) {
		this.userdao = userdao;
	}


	public User login(User user) {
		return userdao.login(user);
	}


	@Override
	public Page<User> getall(int start,int limit,int currentpage) {
		String hql="from Article";
		List<User> list=userdao.getDatas(hql, start, limit);
		int rowCount=userdao.findall(hql);
		Page<User> pageutil= new Page<User>(limit, rowCount, currentpage);
		pageutil.setList(list);
		return pageutil;
	}


	@Override
	public Page<Article> getArticles(int start, int limit, int currentpage,String tablename,String keywords) throws HibernateException, ClassNotFoundException {
		String sql="select md5key,title,summary,remarks,href,author,media_type,sentiment_type,reply_count,view_count,channel,words_num,pub_Time,insert_Time,source,last_Modifier,status from "+tablename+" where status<>2";
		String sql1="select count(md5key) as rowcount from "+tablename+" where status<>2";
		List<Article> list=userdao.getSQLDatas(sql, start, limit,"com.trytry.entity.ArticleSearch",keywords);
		int rowCount=userdao.sqlfindall(sql1,keywords);
		Page<Article> pageutil= new Page<Article>(limit, rowCount, currentpage);
		pageutil.setList(list);
		return pageutil;
	}
}
